<template>
  <div>
    <template v-for="(item, index) in options">
      <template v-if="values.includes(item.value)">
        <p-tag
          :bgc="rancolor(item)"
          :text="item.label"
          :key="item.value + ''"
          :index="index"
          :class="item.elTagClass"
        />
      </template>
    </template>
  </div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  // 数据
  options: {
    type: Array,
    default: null
  },
  // 当前的值
  value: [Number, String, Array]
})

const values = computed(() => {
  if (props.value !== null && typeof props.value !== 'undefined') {
    return Array.isArray(props.value) ? props.value : [String(props.value)]
  } else {
    return []
  }
})

const color = ['#409eff', '#fc5531', '#16b251', '#b07ffd', '#fc5633']
// 黄色
const yeallow = 'yeallow'
// 红色
const red = 'red'
// 蓝色
const blue = 'blue'
// 灰色
const huise = '#c4c6ca'

const A = ['暂停', '停用']
const B = ['告警', '报警', '预警']
const C = ['停机', '挂机']
const D = ['维修', '保养', '点检', '巡检']
const E = ['启动', '运行', '开启', '在用']

const rancolor = val => {
  if (A.includes(val.label)) {
    return 'red'
  } else if (B.includes(val.label)) {
    return 'yeallow'
  } else if (C.includes(val.label)) {
    return '#c4c6ca'
  } else if (D.includes(val.label)) {
    return '#409eff'
  } else if (E.includes(val.label)) {
    return '#43b244'
  }

  // return Math.floor(Math.random() * (color.length - 0) + 1)
}
</script>

<style scoped>
.el-tag + .el-tag {
  margin-left: 10px;
}
</style>
